package com.denlaku.longan.datac;

import com.denlaku.longan.util.Maps;

import java.util.Map;

/**
 * @author tianx
 */

public enum JdbcType {

	// ------ string ------
	CHAR("CHAR", DataType.STRING),
	NCHAR("NCHAR", DataType.STRING),
	VARCHAR("VARCHAR", DataType.STRING),
	VARCHAR2("VARCHAR2", DataType.STRING),
	NVARCHAR2("NVARCHAR2", DataType.STRING),
	TINYTEXT("TINYTEXT", DataType.STRING),
	TEXT("TEXT", DataType.STRING),
	MEDIUMTEXT("MEDIUMTEXT", DataType.STRING),
	LONGTEXT("LONGTEXT", DataType.STRING),
	// ------ number ------
	TINYINT("TINYINT", DataType.NUMBER),
	TINYINT_UNSIGNED("TINYINT UNSIGNED", DataType.NUMBER),
	SMALLINT("SMALLINT", DataType.NUMBER),
	SMALLINT_UNSIGNED("SMALLINT UNSIGNED", DataType.NUMBER),
	MEDIUMINT("MEDIUMINT", DataType.NUMBER),
	MEDIUMINT_UNSIGNED("MEDIUMINT UNSIGNED", DataType.NUMBER),
	INT("INT", DataType.NUMBER),
	INT_UNSIGNED("INT UNSIGNED", DataType.NUMBER),
	INTEGER("INTEGER", DataType.NUMBER),
	INTEGER_UNSIGNED("INTEGER UNSIGNED", DataType.NUMBER),
	BIGINT("BIGINT", DataType.NUMBER),
	BIGINT_UNSIGNED("BIGINT UNSIGNED", DataType.NUMBER),
	FLOAT("FLOAT", DataType.NUMBER),
	DOUBLE("DOUBLE", DataType.NUMBER),
	DECIMAL("DECIMAL", DataType.NUMBER),
	NUMBER("NUMBER", DataType.NUMBER),
	LONG("LONG", DataType.NUMBER),
	// ------ date ------
	DATE("DATE", DataType.DATE),
	DATETIME("DATETIME", DataType.DATE),
	YEAR("YEAR", DataType.DATE),
	TIME("TIME", DataType.DATE),
	TIMESTAMP("TIMESTAMP", DataType.DATE),
	DATE1111("DATE", DataType.DATE);

	private static final Map<String, String> MAP;

	static {
		JdbcType[] values = JdbcType.values();
		MAP = Maps.ofSize(values.length);
		for (JdbcType value : values) {
			MAP.put(value.getName(), value.getType());
		}
	}

	public static String getDataType(String jdbcType) {
		return MAP.get(jdbcType);
	}

	private final String name;
	private final String type;

	JdbcType(String name, String type) {
		this.name = name;
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}
	
	public boolean eq(String name) {
		return this.getName().equals(name);
	}

}
